var _util = require('util/util.js');

var _cart_servcie = {
    registerCart : function (resolve, reject) {
        _util.request({
            //后端的url
            url: _util.getServerURL('cart/registerCart'),
            method: "POST",
            success: resolve,
            error: reject,
        });
    },
    viewCart : function (resolve, reject) {
        _util.request({
            //后端的url
            url: _util.getServerURL('cart'),
            success: resolve,
            error: reject,
        });
    },
    addItemToCart : function (itemId,resolve, reject) {
        _util.request({
            //后端的url
            url: _util.getServerURL('cart/items/'+itemId),
            method: "POST",
            success: resolve,
            error: reject,
        });
    },
    deleteItemFromCart : function (itemId,resolve, reject) {
        _util.request({
            //后端的url
            url: _util.getServerURL('cart/items/'+itemId),
            method: "DELETE",
            success: resolve,
            error: reject,
        });
    },
    updateItemQtyFromCart : function (itemId,qty,resolve, reject) {
        _util.request({
            //后端的url
            url: _util.getServerURL('cart/items/'+itemId + "/quantity/" +qty ),
            method: "PATCH",
            success: resolve,
            error: reject,
        });
    },
}

module.exports = _cart_servcie;